import java.util.regex.Matcher;
import java.util.regex.Pattern;

/*
purpose find match only a line start 
*/
public class testGroupPattern
{
    static String pattern = "(\\w+)\\s(\\1)";
   static  String input = "He said that that was the the correct answer."; 	
public static void main(String[] args)
 {
  	
testGroupPattern tfp=new testGroupPattern();
tfp.testSyntax(input);
}
public void testSyntax(String data)
 {

			Pattern p = Pattern.compile(pattern, Pattern.MULTILINE);
			Matcher m = p.matcher(data);
 			while(m.find())
			{
 System.out.printf("Total Group:%s....\n",m.group(0));
 System.out.printf("Total Group:%02d,%s,%d,%d,....\n",m.groupCount(),m.group(1),m.start(1),m.end(1));
 System.out.printf("Total Group:%02d,%s,%d,%d,....\n",m.groupCount(),m.group(2),m.start(2),m.end(2));
			 }
 	}
}